<!DOCTYPE html>
<html lang="zh">
<head>
    <meta charset="UTF-8" />
    <title>{$Think.config.amis.login.title} 登录</title>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <link rel="icon" type="image/x-ico" href="{$Think.config.amis.logo}"/>
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1"/>
    <meta http-equiv="X-UA-Compatible" content="IE=Edge" />
    {load href="/static/amis-sdk/helper.css" /}
    <link rel="stylesheet" href="/static/amis-sdk/sdk.css">
    <link rel="stylesheet" href="/static/amis-sdk/{$Think.config.amis.amis_theme|default='sdk'}.css">
    <style>
        html,
        body,
        .app-wrapper {
            position: relative;
            width: 100%;
            height: 100%;
            margin: 0;
            padding: 0;
            touch-action: pan-y;
        }
        {if !$Request.isMobile}
        .app-wrapper{
            background: {$Think.config.amis.login.bg|raw} no-repeat;
            background-size: cover;
        }
        {/if}
        :root {
            --Form-item-gap: 1.3rem;
            --InputGroup-height: 2.5rem;
            --Button-height: 2.5rem;
            --InputGroup-paddingX: .6rem;
            --InputGroup-addOn-bg: var(--Form-input-bg);
            /* --fontSizeBase: .9rem; */
        }
        .amis-scope .cxd-Icon{height: 1rem}
        .amis-scope .cxd-TextControl-input input{height: 100% !important;}
        .amis-scope .cxd-TextControl-input:hover{border:var(--Form-input-borderWidth) solid var(--Form-input-borderColor)}
        .amis-scope .cxd-InputGroup .cxd-TextControl-input{border-left-width: 0;padding-left: 0;}
        .code_img{cursor: pointer;}
            /* 配置样式 */
        .login_layout{
            {if !$Request.isMobile}
                /* 仅 pc 生效 */
                /* 宽度 默认 400px */
                width: {$Think.config.amis.login.width|default='400px'};
                /* 登录窗口靠左还是靠右 */
                {if $Think.config.amis.login.align == 'left'} left:0;{else /}right:0;{/if}
                /*  是否浮动  */
                {if $Think.config.amis.login.float}
                    border-radius:2px;
                    margin:10rem 6rem !important;
                    height:auto;
                {else /}
                    padding-top: 8rem !important;
                    height:100vh;
                {/if}

            {/if}
        }
        .amis-scope .cxd-InputGroup .cxd-TextControl-input:not(:first-child) {
          height: 40px;
        }
        .amis-scope .h-2\.5 {
          height: auto;
        }
    </style>
</head>
<body>
<div id="root" class="app-wrapper"></div>
{load href="/static/amis-sdk/sdk.js" /}
<script type="text/javascript">
    (function () {
        let amis = amisRequire('amis/embed');
        // 通过替换下面这个配置来生成不同页面
        let amisJSON = {
            "type": "wrapper",
            "className": "fixed login_layout m:h-screen m:w-full bg-gray-50",
            "body": {
                "type": "form",
                // "className": "h-full pc:p-9 m:p-4 m:pt-20",
                "api": {
                    "method":"post",
                    "url":"/login",
                    "adaptor": function (data) {
                        if (data.status !== 0) {
                            // 登录请求提交后，刷新验证码
                            refresh_code();
                        }
                        return data;
                    },
                },
                "redirect": "/",
                "wrapWithPanel": false,
                "body": [
                    {
                        "type":"html",
                        "className":"text-center",
                        "html":"<h1>{$Think.config.amis.login.title}</h1>"
                    },
                    {
                        "type": "input-group",
                        "label": "",
                        "body": [
                            {
                                "type": "icon",
                                "icon": "/static/icon/shield-user-line.svg"
                            },
                            {
                                "type": "input-text",
                                "label": false,
                                "placeholder": "用户名",
                                "name": "name",
                                "required": true
                            }
                        ]
                    },
                    {
                        "type": "input-group",
                        "label": "",
                        "body": [
                            {
                                "type": "icon",
                                "icon": "/static/icon/lock-password-line.svg",
                            },
                            {
                                "type": "input-password",
                                "label": false,
                                "placeholder": "密码",
                                "name": "pwd",
                                "required": true
                            }
                        ]
                    },
                    {
                        "type": "input-group",
                        "label": "",
                        "body": [
                            {
                                "type": "icon",
                                "icon": "/static/icon/shield-check-line.svg"
                            },
                            {
                                "type": "input-text",
                                "label": false,
                                "placeholder": "验证码",
                                "name": "code",
                                "required": true
                            },
                            {
                                "type": "action",
                                "body": {
                                    "type": "image",
                                "height": "38px",
                                "width": "110px",
                                "name":"codeUrl",
                                "imageClassName":"code_img b-none",
                                "imageMode":"original",
                                "src": "/login/verify"
                                },
                                // 点击图片 刷新二维码
                                "onClick": "refresh_code()"
                            }
                        ]
                    },
                    {
                        "label": "登 录",
                        "type": "action",
                        "actionType": "submit",
                        "level": "primary",
                        "className":"w-full h-2.5",
                    },
                    {
                        "type":"html",
                        "className":"text-center",
                        "html":"<p class='mt-10 text-gray-600'>{$Think.config.amis.login.footer}</p>"
                    },
                ]

            }

        };
        let amisScoped = amis.embed('#root', amisJSON);
    })();
    // 刷新验证码
    function refresh_code()
    {
        document.querySelector('.code_img').src = '/login/verify?' + Math.random();
    }
</script>
</body>
</html>
